<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>动态桥梁挠度曲线</title>
    <script src="{{ url_for('static', filename='plotly-latest.min.js') }}"></script>
    <link href="../static/css/bootstrap.min.css" rel="stylesheet">
    <style>
        body {
            background: linear-gradient(135deg, #ffffff 0%, #8e8e8eb8 100%);
            min-height: 100vh;
            margin: 0;
        }
        #plot {
            width: 1200px;
            height: 600px;
            margin: 0 auto;
            position: absolute;
            left: 50%;
            top: 50%;
            transform: translate(-50%, -50%);
            border-radius: 15px;
        }
    
        .btn-container {
            position: absolute;
            top: 40px;
            left: 40px;
        }
        .btn-container.btn {
            margin: 0 1rem;
            padding: 15px 30px;
            font-size: 1.5rem;
            font-weight: 500;
            transition: filter 0.3s ease;
        }
        .btn-container .btn-primary {
            background: linear-gradient(90deg, #2196F3, #00BCD4);
            border: none;
        }
        .btn-container .btn:hover {
            filter: brightness(0.6);
        }
    </style>
</head>
<body>
    <div id="plot"></div>
    <div class="btn-container">
        <a href="/" class="btn btn-primary">返回主页</a>
    </div>
    <script>
        const plotDiv = document.getElementById('plot');
        let layout = {
            title: {
                text: "动态桥梁挠度曲线",
                font: { size: 30, color: 'black' }
            },
            titlefont: { color: 'black' },
            xaxis: {
                title: "位置/m",
                titlefont: { color: 'black', size: 25 },
                tickfont: { color: 'black', size: 15 },
            },
            yaxis: {
                title: "挠度/m",
                titlefont: { color: 'black', size: 25 },
                tickfont: { color: 'black', size: 15 },
            },
            legend: {
                x: 1,
                y: 1,
                xanchor: 'right',
                yanchor: 'top',
                font: { color: 'black', size: 20 }
            },
            margin: {
                l: 150,
                r: 50,
                t: 80,
                b: 80
            },
            plot_bgcolor: '#ffffff',
        };

        fetchData();

        setInterval(fetchData, 20000);

        function fetchData() {
            fetch('/get_data')
                .then(response => response.json())
                .then(data => {
                    const x = data.x;
                    const deflections_point = data.deflections_point;
                    const deflections_dist = data.deflections_dist;
                    Plotly.newPlot(plotDiv, [
                        { x: x, y: deflections_point, name: '集中荷载', type: 'scatter', mode: 'lines+markers'},
                        { x: x, y: deflections_dist, name: '均布荷载', type: 'scatter', mode: 'lines+markers' }
                    ], layout);
                })
                .catch(error => console.error('Error fetching data:', error));
        }

        // 自动恢复页面缩放
        function resetZoom() {
            document.body.style.transform = "scale(1)";
            document.body.style.transformOrigin = "0 0";
        }

        // 监听窗口大小变化
        window.addEventListener("resize", resetZoom);
        window.addEventListener("load", resetZoom);
    </script>
</body>
</html>